package com.api.department.createfolder;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.test.context.ContextConfiguration;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;

import com.api.test.AbstractApiTest;
import com.api.test.AssertApi;
import com.api.test.UrnType;
import com.zyncro.api.IDepartmentApiService;
import com.zyncro.api.exceptions.ZyncroApiException;
import com.zyncro.api.model.ObjectResultApi;

@ContextConfiguration(locations = "classpath:/department/department-toedit.xml")
public class CreateFolder extends AbstractApiTest {
	@Value("#{department_toEdit[owner].appId}")
	private String userUrn;

	@Value("#{department_toEdit[owner].password}")
	private String userPassword;

	@Value("#{department_toEdit.urn}")
	private String iddepartment;

	private String folderUrn = "";

	@BeforeClass
	protected void loginUser() throws Exception {

		getApi().login(userUrn, userPassword);
	}

	@Test
	public void test() throws ZyncroApiException {
		String name = "Folder name 2";
		String description = null;

		ObjectResultApi<String> result = getApi().getService(IDepartmentApiService.class).createFolder(iddepartment, name, description);

		AssertApi.assertUrnType(result.getObject(), UrnType.DOCUMENT);

		this.folderUrn = result.getObject();
	}

	@AfterClass
	public void restoreValues() throws ZyncroApiException {
		getApi().getService(IDepartmentApiService.class).deleteDocument(iddepartment, folderUrn);
	}
}
